package com.tjmc.company.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.entity.CompanyReadRecordsEntity;
import com.tjmc.company.service.CompanyReadRecordsService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 企业浏览记录
 *
 * @author recruit
 * @date 2024-11-14 16:15:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/companyReadRecords" )
@Tag(description = "companyReadRecords" , name = "企业浏览记录管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CompanyReadRecordsController {

    private final CompanyReadRecordsService companyReadRecordsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param companyReadRecords 企业浏览记录
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getCompanyReadRecordsPage(@ParameterObject Page page, @ParameterObject CompanyReadRecordsEntity companyReadRecords) {
        LambdaQueryWrapper<CompanyReadRecordsEntity> wrapper = Wrappers.lambdaQuery(companyReadRecords);
        return R.ok(companyReadRecordsService.selectPage(page, companyReadRecords.getCompanyId()));
    }

    /**
     * 分页查询-个人被浏览企业
     * @param page 分页对象
     * @param accountId 个人用户ID
     * @return
     */
    @Operation(summary = "个人被企业浏览分页查询" , description = "个人被企业浏览分页查询" )
    @GetMapping("/page/{accountId}" )
    public R getCompanyReadRecordsPage(@ParameterObject Page page, @PathVariable Long accountId) {
        return R.ok(companyReadRecordsService.getCompanyReadRecords(page, accountId));
    }

    /**
     * 通过条件查询企业浏览记录
     * @param companyReadRecords 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject CompanyReadRecordsEntity companyReadRecords) {
        return R.ok(companyReadRecordsService.list(Wrappers.query(companyReadRecords)));
    }

    /**
     * 新增企业浏览记录
     * @param companyReadRecords 企业浏览记录
     * @return R
     */
    @Operation(summary = "新增企业浏览记录" , description = "新增企业浏览记录" )
    @SysLog("新增企业浏览记录" )
    @PostMapping
    public R save(@RequestBody CompanyReadRecordsEntity companyReadRecords) {
        return R.ok(companyReadRecordsService.save(companyReadRecords));
    }

    /**
     * 修改企业浏览记录
     * @param companyReadRecords 企业浏览记录
     * @return R
     */
    @Operation(summary = "修改企业浏览记录" , description = "修改企业浏览记录" )
    @SysLog("修改企业浏览记录" )
    @PutMapping
    public R updateById(@RequestBody CompanyReadRecordsEntity companyReadRecords) {
        return R.ok(companyReadRecordsService.updateById(companyReadRecords));
    }

    /**
     * 通过id删除企业浏览记录
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除企业浏览记录" , description = "通过id删除企业浏览记录" )
    @SysLog("通过id删除企业浏览记录" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(companyReadRecordsService.removeBatchByIds(CollUtil.toList(ids)));
    }
}
